package com.atguigu.sugar.mapper;

import com.atguigu.sugar.bean.Spu;
import com.atguigu.sugar.bean.Tm;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

public interface ProductMapper {
    
    // 计算指定日期的总的交易额
    // 2021-12-12   20211212
    @Select("SELECT sum(order_amount) AS order_amount\n" +
        "FROM product_stats_2021\n" +
        "WHERE toYYYYMMDD(stt) = #{date}\n")
    BigDecimal gmv(@Param("date") int date);
    
    @Select("SELECT\n" +
        "    category3_name,\n" +
        "    sum(order_amount) AS order_amount\n" +
        "FROM product_stats_2021\n" +
        "WHERE toYYYYMMDD(stt) = #{date}\n" +
        "GROUP BY category3_name\n")
    List<Map<String, Object>> gmvByC3(@Param("date") int date);
    
    @Select("SELECT\n" +
        "    spu_name,\n" +
        "    sum(order_amount) AS order_amount\n" +
        "FROM product_stats_2021\n" +
        "WHERE toYYYYMMDD(stt) =  #{date}\n" +
        "GROUP BY spu_name\n")
    List<Spu> gmvBySpu(@Param("date") int date);
    
    
    @Select("SELECT\n" +
        "    tm_name,\n" +
        "    sum(order_amount) AS order_amount\n" +
        "FROM product_stats_2021\n" +
        "WHERE toYYYYMMDD(stt) = #{date}\n" +
        "GROUP BY tm_name\n")
    List<Tm> gmvByTm(@Param("date") int date);
    
    
    
}
